package com.api.shopapi.mapper;

import com.api.shopapi.entity.CallRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CallRecordMapper {

    @Insert("insert into call_record (CallRecordCode," +
            "CalledPhone," +
            "AccessTime," +
            "Duration," +
            "Account," +
            "RecordUrl," +
            "CallingPhone," +
            "StartTime," +
            "recStatus," +
            "Address) " +
            "value(#{callRecord.CallRecordCode}," +
            "#{callRecord.CalledPhone}," +
            "#{callRecord.AccessTime}," +
            "#{callRecord.Duration}," +
            "#{callRecord.Account}," +
            "#{callRecord.RecordUrl}," +
            "#{callRecord.CallingPhone}," +
            "#{callRecord.StartTime}," +
            "#{callRecord.RecStatus}," +
            "#{callRecord.Address})")
    public int insert(@Param("callRecord") CallRecord callRecord);

    @Update("update call_record " +
            "set " +
            "CalledPhone = #{callRecord.CalledPhone}," +
            "AccessTime = #{callRecord.AccessTime}," +
            "Duration = #{callRecord.Duration}," +
            "Account = #{callRecord.Account},"+
            "RecordUrl = #{callRecord.RecordUrl} "+
            "CallingPhone = #{callRecord.CallingPhone} "+
            "StartTime = #{callRecord.StartTime} "+
            "recStatus = #{callRecord.RecStatus} "+
            "Address = #{callRecord.Address} "+
            "where CallRecordCode=#{callRecord.CallRecordCode}")
    public int update(@Param("callRecord") CallRecord callRecord);

    @Select("select * from call_record  order by StartTime desc")
    public List<CallRecord> getList();

    @Select("SELECT * FROM call_record WHERE CalledPhone=#{phone} or CallingPhone=#{phone} order by StartTime desc")
    public List<CallRecord> getSeatsList(@Param("phone") String phone);

    @Select("select * from call_record where CallRecordCode=#{callRecordCode} limit 1")
    public CallRecord getByCallRecordCode(@Param("callRecordCode") String callRecordCode);

    @Select("select * from call_record where UserCode = #{userCode} order by CreateTime desc")
    public List<CallRecord> getListByUserCode(String userCode);
}
